<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<link rel="stylesheet" href="/resources/plugins/datatables/dataTables.bootstrap.css" />
		<style>
</style>
	</ui:define>
	<ui:define name="content">
		<div class='full-center-content-scroll-noheader'>
			<h:form id="form3">
				<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
					<p:commandButton value="是" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
					<p:commandButton value="否" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
				</p:confirmDialog>
				<p:growl id="msgs" showDetail="true" />
				<div class="box box-solid with-border">
					<div class="box-header">
						<p:outputLabel for="popup1" value="创建时间：" />
						<p:calendar id="popup1" navigator="true" value="#{alarmMessageConfigController.queryDate1}"
							pattern="yyyy-MM-dd" maxdate="Date()">
						</p:calendar>
						<p:outputLabel for="popup2" value="至 " style="margin-right:5px;margin-left:5px;" />
						<p:calendar id="popup2" navigator="true" value="#{alarmMessageConfigController.queryDate2}"
							pattern="yyyy-MM-dd" maxdate="Date()" style="margin-right:10px">
						</p:calendar>
						<p:outputLabel value="消息类型：" style="margin-left:10px" />
						<h:selectOneMenu id="msgType" value="#{alarmMessageConfigController.typeQuery}"
							style="width:180px;margin-right:20px;height:30px">
							<f:selectItem itemLabel="全部" itemValue="" />
							<f:selectItems itemLabel="#{item.description}" itemValue="#{item.id}"
								value="#{alarmMessageConfigController.msgTypeList}" var="item">
							</f:selectItems>
						</h:selectOneMenu>
						<p:outputLabel value="消息状态：" />
						<h:selectOneMenu id="msgTypeQuery" value="#{alarmMessageConfigController.statusQuery}"
							style="width:130px;margin-right:20px;height:30px">
							<f:selectItem itemLabel="未过期" itemValue="0" />
							<f:selectItem itemLabel="已过期" itemValue="1" />
							<f:selectItem itemLabel="全部" itemValue="" />
						</h:selectOneMenu>
						<p:commandButton value="查询" actionListener="#{alarmMessageConfigController.query}"
							update=" form3:dataTb" icon="ui-icon-search">
						</p:commandButton>
						<p:commandButton value="重置" actionListener="#{alarmMessageConfigController.init}"
							update="form3" icon="ui-icon-refresh">
						</p:commandButton>
					</div>
				</div>
				<p:toolbar id="btnBar">
					<f:facet name="left">
						<p:commandButton value="编辑" id="editBtn"
							disabled="#{alarmMessageConfigController.selected==null}" oncomplete="PF('editDlg').show()"
							rendered="#{s:hasPermission(session,'xtsz_gjxxwh_bj')}" process="@this"
							actionListener="#{alarmMessageConfigController.edit}"
							update="editForm:editDlg overdueBtn stationForm" icon="fa fa-pencil" />
						<!-- <p:commandButton value="删除" id="delBtn"
							disabled="#{alarmMessageConfigController.selected==null}"
							rendered="#{s:hasPermission(session,'xtsz_gjxxwh_sc')}"
							actionListener="#{alarmMessageConfigController.deleteById}"
							update="form3:msgs form3:dataTb form3:delBtn form3:editBtn form3:overdueBtn"
							icon="fa fa-trash">
							<p:confirm header="提示" message="确定要删除么？" icon="ui-icon-alert" />
						</p:commandButton> -->
						<p:commandButton value="置为过期" id="overdueBtn"
							disabled="#{alarmMessageConfigController.selected==null}" process="@this"
							rendered="#{s:hasPermission(session,'xtsz_gjxxwh_zwgq')}"
							actionListener="#{alarmMessageConfigController.overdueByHand}" update="dataTb msgs"
							icon="ui-icon-contact">
							<p:confirm header="提示" message="确定要将本条数据置为过期么？" icon="ui-icon-alert" />
						</p:commandButton>
					</f:facet>
				</p:toolbar>
				<p:dataTable id="dataTb" var="messages" emptyMessage="无记录" rowIndexVar="ite"
					value="#{alarmMessageConfigController.model}" rowKey="#{messages.id}"
					selection="#{alarmMessageConfigController.selected}" rows="20" paginator="true" lazy="true"
					paginatorTemplate="{Customization} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="20,50,100" paginatorPosition="bottom">
					<f:facet name="{Customization}">
						<p:outputLabel value="总计：#{alarmMessageConfigController.model.rowCount} 条记录"
							style="margin-right:20px;" />
					</f:facet>
					<p:ajax event="rowSelectRadio" listener="#{alarmMessageConfigController.onRowSelect}"
						update="form3:btnBar" />
					<p:column selectionMode="single" style="text-align:center;width:60px" />
					<p:column width="60" headerText="序号">
						<h:outputText value="#{ite+1}" />
					</p:column>
					<p:column headerText="消息内容">
						<h:outputText value="#{messages.content}" />
					</p:column>
					<p:column headerText="创建时间">
						<h:outputText value="#{messages.createTime}">
							<f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" />
						</h:outputText>
					</p:column>
					<p:column headerText="消息类型">
						<h:outputText value="#{alarmMessageConfigController.getDescriptionText(messages.msgType)}" />
					</p:column>
					<p:column headerText="消息状态">
						<h:outputText value="#{messages.stausText}" />
					</p:column>
					<p:column headerText="变电站">
						<h:outputText value="#{messages.stationName}" />
					</p:column>
					<p:column headerText="一次设备">
						<h:outputText value="#{messages.primaryName}" />
					</p:column>
					<p:column headerText="二次设备">
						<h:outputText value="#{messages.secondaryName}" />
					</p:column>
				</p:dataTable>
			</h:form>
			<h:form id="editForm">
				<p:dialog widgetVar="editDlg" header="编辑告警消息" modal="true" id="editDlg" width="600" height="400">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton id="createSaveBtn" value="保存" style="float: right;" icon="fa fa-floppy-o"
								update="form3:dataTb form3:msgs form3:editBtn form3:overdueBtn"
								actionListener="#{alarmMessageConfigController.save}" oncomplete="PF('editDlg').hide()" />
						</f:facet>
					</p:toolbar>
					<p:outputPanel id="editDetail" style="width:100%;">
						<p:panelGrid style="width:100%">
							<p:row>
								<p:column>
									<h:outputText value="变电站" />
								</p:column>
								<p:column>
									<p:inputText value="#{alarmMessageConfigController.selected.stationName}" id="station_id"
										onclick="PF('stationDialog').show()" style="width:100%" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="一次设备" />
								</p:column>
								<p:column>
									<p:inputText value="#{alarmMessageConfigController.selected.primaryName}" id="primary_id"
										style="width:80%" readonly="#{alarmMessageConfigController.selected.stationName==null}">
										<p:ajax event="valueChange" listener="#{alarmMessageConfigController.editPrimaryName()}"
											update="content_id" />
									</p:inputText>
									<p:commandButton disabled="#{alarmMessageConfigController.selected.stationName==null}"
										value="选择" actionListener="#{alarmMessageConfigController.initPrimaryTree}"
										oncomplete="PF('primaryDialog').show()" update=":primaryForm" style="margin-left:5px"
										id="primaryBtn" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="二次设备" />
								</p:column>
								<p:column>
									<p:inputText value="#{alarmMessageConfigController.selected.secondaryName}"
										id="secondary_id" style="width:80%"
										readonly="#{alarmMessageConfigController.selected.stationName==null}">
										<p:ajax event="valueChange" listener="#{alarmMessageConfigController.editSecondaryName()}"
											update="content_id" />
									</p:inputText>
									<p:commandButton disabled="#{alarmMessageConfigController.selected.stationName==null}"
										value="选择" actionListener="#{alarmMessageConfigController.initSecondaryTree}"
										oncomplete="PF('secondaryDialog').show()" update=":secondaryForm" style="margin-left:5px"
										id="secondaryBtn" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="消息内容" />
								</p:column>
								<p:column>
									<h:inputTextarea id="content_id" label="name"
										value="#{alarmMessageConfigController.selected.content}" required="true"
										requiredMessage="消息内容为必填项" rows="3" style="width:100%" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="创建时间" />
								</p:column>
								<p:column>
									<p:calendar value="#{alarmMessageConfigController.selected.createTime}" navigator="true"
										pattern="yyyy-MM-dd HH:mm:ss" required="true" requiredMessage="创建时间为必填项" />
								</p:column>
							</p:row>
						</p:panelGrid>
					</p:outputPanel>
				</p:dialog>
			</h:form>
			<h:form id="stationForm">
				<p:dialog widgetVar="stationDialog" header="关联变电站" modal="true" id="stationDialog" width="450"
					height="650">
					<p:toolbar>
						<f:facet name="left">
							<p:autoComplete placeholder="输入变电站首字母可查" id="station_id" size="20"
								value="#{alarmMessageConfigController.station}"
								completeMethod="#{stationDataViewController.complateStation}" scrollHeight="400"
								style="float:left;">
								<p:ajax update="station_id stationTree" event="itemSelect"
									listener="#{alarmMessageConfigController.reGenStationTree}" />
							</p:autoComplete>
							<p:commandButton icon="fa fa-refresh" style="margin-left:3px;height:30px;"
								update="station_id stationTree"
								actionListener="#{alarmMessageConfigController.refreshStationTree()}" />
						</f:facet>
						<f:facet name="right">
							<p:commandButton value="确定" icon="ui-icon-disk" oncomplete="PF('stationDialog').hide()"
								id="stationBtn"
								update="editForm:station_id editForm:primary_id editForm:secondary_id editForm:content_id editForm:primaryBtn editForm:secondaryBtn"
								actionListener="#{alarmMessageConfigController.changeStation()}"
								disabled="#{alarmMessageConfigController.stationSelectedNode==null}" />
						</f:facet>
					</p:toolbar>

					<p:tree value="#{alarmMessageConfigController.stationRoot}" var="node" dynamic="true"
						selectionMode="single" id="stationTree" widgetVar="stationTree" animate="true"
						style="border:0">
						<p:ajax event="expand" update="stationTree"
							listener="#{alarmMessageConfigController.onStationNodeExpand}" />
						<p:ajax event="select" update="stationForm:stationBtn"
							listener="#{alarmMessageConfigController.onStationNodeSelect}" />
						<p:treeNode type="dept" icon="fa fa-home">
							<h:outputText value="#{node}" />
						</p:treeNode>
						<p:treeNode type="station">
							<h:outputText value="#{node}" />
						</p:treeNode>
					</p:tree>
				</p:dialog>
			</h:form>
			<h:form id="primaryForm">
				<p:dialog widgetVar="primaryDialog" header="关联一次设备" modal="true" id="primaryDialog" width="450"
					height="650">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton value="确定" icon="ui-icon-disk" oncomplete="PF('primaryDialog').hide()"
								update="editForm:primary_id editForm:content_id" id="primaryBtn"
								actionListener="#{alarmMessageConfigController.changePrimary()}"
								disabled="#{alarmMessageConfigController.primarySelectedNode==null}" />
							<p:commandButton icon="ui-icon-cancel" value="关闭" type="button"
								onclick="PF('primaryDialog').hide()" style="margin-left:5px" />
						</f:facet>
					</p:toolbar>
					<p:tree value="#{alarmMessageConfigController.primaryRoot}" var="node" dynamic="true"
						selectionMode="single" id="primaryTree" widgetVar="primaryTree" animate="true"
						style="border:0">
						<p:ajax event="expand" update="primaryTree"
							listener="#{alarmMessageConfigController.onPrimaryNodeExpand}" />
						<p:ajax event="select" update="primaryForm:primaryBtn"
							listener="#{alarmMessageConfigController.onPrimaryNodeSelect}" />
						<p:treeNode type="station" icon="fa fa-home">
							<h:outputText value="#{node}" />
						</p:treeNode>
						<p:treeNode type="equipment">
							<h:outputText value="#{node}" />
						</p:treeNode>
						<p:treeNode type="type" icon="fa fa-home">
							<h:outputText value="#{node}" />
						</p:treeNode>
					</p:tree>
				</p:dialog>
			</h:form>
			<h:form id="secondaryForm">
				<p:dialog widgetVar="secondaryDialog" header="关联二次设备" modal="true" id="secondaryDialog"
					width="450" height="650">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton value="确定" icon="ui-icon-disk" oncomplete="PF('secondaryDialog').hide()"
								update="editForm:secondary_id editForm:content_id" id="secondaryBtn"
								actionListener="#{alarmMessageConfigController.changeSecondary()}"
								disabled="#{alarmMessageConfigController.secondarySelectedNode==null}" />
							<p:commandButton icon="ui-icon-cancel" value="关闭" type="button"
								onclick="PF('secondaryDialog').hide()" style="margin-left:5px" />
						</f:facet>
					</p:toolbar>
					<p:tree value="#{alarmMessageConfigController.secondaryRoot}" var="node" dynamic="true"
						selectionMode="single" id="secondaryTree" widgetVar="secondaryTree" animate="true"
						style="border:0">
						<p:ajax event="expand" update="secondaryTree"
							listener="#{alarmMessageConfigController.onSecondaryNodeExpand}" />
						<p:ajax event="select" update="secondaryForm:secondaryBtn"
							listener="#{alarmMessageConfigController.onSecondaryNodeSelect}" />
						<p:treeNode type="station" icon="fa fa-home">
							<h:outputText value="#{node}" />
						</p:treeNode>
						<p:treeNode type="equipment">
							<h:outputText value="#{node}" />
						</p:treeNode>
						<p:treeNode type="type" icon="fa fa-home">
							<h:outputText value="#{node}" />
						</p:treeNode>
					</p:tree>
				</p:dialog>
			</h:form>
		</div>
	</ui:define>
	<ui:define name="contentend">
		<script src="/resources/plugins/datatables/jquery.dataTables.js"></script>
		<script src="/resources/plugins/datatables/dataTables.bootstrap.min.js"></script>
		<script src="/resources/js/tables/mytable.js"></script>
		<script>
			function onSelectDivClick() {
				var div = $('#selectDiv');
				if (div.hasClass('in')) {
					div.collapse('hide');
					$('#selectButtonIcon').removeClass("fa fa-caret-up");
					$('#selectButtonIcon').addClass("fa fa-caret-down");
				} else {
					div.collapse('show');
					$('#selectButtonIcon').removeClass("fa fa-caret-down");
					$('#selectButtonIcon').addClass("fa fa-caret-up");
				}
			}
		</script>
	</ui:define>
</ui:composition>
